spatial.funk <- function(n)
{
	library(deSolve)
	source('connectivity.R')

	fn <- function(t, X, params) {
		T <- X[1:(n*n)]
		Y <- X[(n*n+1):(2*n*n)]
		V <- X[(2*n*n+1):(3*n*n)]

		with(params, {
			dT <- b - d*T - e*T*V
			dY <- e*T*V - u*Y
			dV <- p*Y - c*V + (V %*% C)*mV/8
			list(c(as.vector(dT),as.vector(dY),as.vector(dV)))
		})
	}

	params <- list(
		b=1, d=0.1, e=0.001, u=0.5, p=1000, c=10,
		mV=0.9, C=periodic.matrix(n)
	)

	T0 <- params$b / params$d
	# virus center grid inoculum
	X0 <- c(rep(T0,n*n), rep(0,2*n*n))
	X0[2*n*n + (n+1)*(n+1)/2-n] <- 10

	stopifnot(length(X0) == 3*n*n)
	ode(X0, seq(0,100,0.01), fn, params, 'euler')
	#ode.2D(X0, seq(0,100,0.01), fn, params, 3, c(n,n), 'euler')
}
